<?php

/* 
 * 商家模型
 * @author wyb
 */
namespace Qwadmin\Model;
class CustomerModel extends BaseModel {
    
    //自动组合入库数据
    protected $_auto = array(
        array( 'create_time' , 'time' , 1 , 'function' ),
        array( 'status' , '1' , 1 )
    );
    
    
    //插入前操作
    protected function _before_insert(&$data, $options) {
        $data['key'] = $this->__authKey();
        
    }
    
    
    /**
     * 自动生成key
     */
    private function __authKey() {
        $str = 'ABC123456DEHJHIklmnopqrstJKL0123456789MNOPQRSTklmnopqrstUVWXY0123456789Zabcdefghijklmnopqrstuvwxyz0123456789';
        $len_str = strlen( $str );
        $key_str = '';
        for( $i = 1; $i <= 50; $i++ ) {
            $key_str .= $str[ rand( 0 , $len_str - 1 ) ];
        }
        if( $this->where(array('key' => $key_str ) )->find() ) {
            return $this->__authKey();
        }
        return $key_str;
    }
}

